import { Component, OnInit } from '@angular/core';
import { LoginInfoService } from '../../.././services/login-info.service';
import { HttpService } from '../../.././services/http.service';
import { commService } from '../../../services/comm.service';
import { BaseUiService } from '../../../services/base-ui.service';
// import { PdfViewerModule } from 'ng2-pdf-viewer';

@Component({
  selector: 'app-certificate',
  templateUrl: './certificate.page.html',
  styleUrls: ['./certificate.page.scss'],
})
export class CertificatePage implements OnInit {
  slideOpts = {
    effect: "flip", //轮播效果
    autoplay: {
      delay: 4000
    },
    loop: false
  };
  public resultList: Array<object>;
  public imglist: Array<string>;
  public isShowimg: boolean;
  public pdfSrc: '';
  public isShowPdf = false;
  public dataLength: number = 0;
  constructor(
    public LoginInfoService: LoginInfoService,
    public commService: commService,
    public httpService: HttpService,
    public BaseUiService: BaseUiService,
    // public PdfViewerModule: PdfViewerModule
  ) { }

  ngOnInit() {
    this.isShowimg = false;
    this.getData();
  }

  getData(){
    this.dataLength = 0;
    let params = {
      pageSize:10000,
      currentPage: 1,
      idCard: this.LoginInfoService.getlocal('user').idCard
      // idCard:'320112199209251211'
    }
    this.httpService.getAnnexList(params).then(
      res => {
        if(res['code']== 200){
          for(let i of res['item']){
            this.dataLength++
          }
          this.resultList = res['item'];
        }
      }
    )
  }

  shutDownPdf(){
    console.log(1111111111)
    this.isShowPdf = false;
    this.pdfSrc = '';
  }

  //关闭轮播图
  iconclick(){
    this.imglist = [];
    this.isShowimg = false;
  }

  //预览证书图片
  showImg(item){
    this.imglist = [];
    this.imglist.push(item.certificatePath);
    this.isShowimg = true;
  }

  //预览证书pdf
  showPdf(item){
    if(item.fileType == 'pdf'){
      this.pdfSrc = item.filePath;
      this.isShowPdf = true;
    }else if(item.fileType == 'jpg' || item.fileType == 'png' || item.fileType == 'jpeg' || item.fileType == 'JPG' || item.fileType == 'PNG' || item.fileType == 'JPEG'){
      this.imglist = [];
      this.imglist.push(item.filePath);
      this.isShowimg = true;
    }else{
      this.BaseUiService.showToast('app当前不支持打开此文件类型','warning','top')
    }
  }

  //下载downloadcl
  downloadcl(url:any){
    this.commService.downPic(url)
  }
  
}
